package leetcode.code1408;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import leetcode.IDebug;

//执行用时：5 ms, 在所有 Java 提交中击败了32.52%的用户
//
//内存消耗：40.6 MB, 在所有 Java 提交中击败了52.43%的用户
//
//通过测试用例：67 / 67
public class Solution5 implements IDebug {

	public List<String> stringMatching(String[] words) {
		Arrays.sort(words, (a, b) -> b.length() - a.length());
		List<String> ans = new ArrayList<>();
		for (int i = 0; i < words.length; i++) {
			String word1 = words[i];
			if (ans.indexOf(word1) >= 0) {
				continue;
			}
			for (int j = i + 1; j < words.length; j++) {
				String word2 = words[j];
//				if (word1.length() == word2.length()) {
//					continue;
//				}
				if (ans.indexOf(word2) < 0 && word1.indexOf(word2) >= 0) {
					ans.add(word2);
				}
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution5 so = new Solution5();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
